package com.xcdh.test.service.impl;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.test.entity.One;
import com.xcdh.test.mapper.OneMapper;
import com.xcdh.test.service.OneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class OneServiceImpl extends ServiceImpl<OneMapper, One> implements OneService {

    @Autowired
    private OneMapper oneMapper ;
    @Override
    public One selectById(Integer id) {
        One o = new One() ;
        o.setId(id);
        JSONObject entries = oneMapper.selectOneId(o);
        return JSONUtil.toBean(entries , One.class) ;
    }

    @Override
    public List<One> selectByChild(Integer id) {
        List<JSONObject> jsonObjects = oneMapper.selectChild(id);
        List<One> oneList = jsonObjects.stream()
                .map(jo -> JSONUtil.toBean(jo, One.class))
                .collect(Collectors.toList());
        return oneList ;
    }
}
